﻿@inherits AdminCompontentBase

<DefaultSheetDialog Value="Visible" ValueChanged=UpdateVisible Title="@T("Add Custom Login")">
    <MForm Model=CustomLogin EnableValidation @ref="Form" EnableI18n>
        <AutoHeight Overflow>
            <HeaderContent>
                <div class="d-flex">
                    <div class="mx-auto">
                        <SLabeledRadioGroup @bind-Value="Tab" Dense>
                            @foreach (var tab in new List<string> { CustomLoginTab.BasicInformation, CustomLoginTab.Login, CustomLoginTab.Register })
                            {
                                <SLabeledRadio Value="tab" TValue="string" MinWidth=70>
                                    @T(tab)
                                </SLabeledRadio>
                            }
                        </SLabeledRadioGroup>
                    </div>
                </div>
            </HeaderContent>
            <AutoHeightContent>
                <MWindow Value="Tab" Class="full-height">
                    <MWindowItem Value="CustomLoginTab.BasicInformation" Class="my-12">
                        @if (ClientSelectRef?.Client?.LogoUri is not null)
                        {
                            <div class="d-flex mb-12">
                                <MAvatar Class="mx-auto" Size=80>
                                    <img src="@ClientSelectRef?.Client?.LogoUri" />
                                </MAvatar>
                            </div>
                        }
                        <MRow Class="mb-6">
                            <MCol>
                                <STextField @bind-Value="CustomLogin.Name" Required Label="@T("TitleName")" />
                            </MCol>
                            <MCol>
                                <STextField @bind-Value="CustomLogin.Title" Required Label="@T("Title")" />
                            </MCol>
                        </MRow>
                        <MRow>
                            <MCol>
                                <ClientSelectForCustomLogin @ref="ClientSelectRef" @bind-Value="CustomLogin.ClientId" />
                            </MCol>
                        </MRow>
                    </MWindowItem>
                    <MWindowItem Value="CustomLoginTab.Login" Class="my-12">
                        <ConfigLogin @bind-Value="CustomLogin.ThirdPartyIdps" Logo="@ClientSelectRef?.Client?.LogoUri" Title="@CustomLogin.Title" />
                    </MWindowItem>
                    <MWindowItem Value="CustomLoginTab.Register" Class="my-12">
                        <ConfigRegister @bind-Value="CustomLogin.RegisterFields" Logo="@ClientSelectRef?.Client?.LogoUri" Title="@CustomLogin.Title" />
                    </MWindowItem>
                </MWindow>
            </AutoHeightContent>
            <FooterContent>
                <div class="d-flex">
                    <EnableSwitch @bind-Value="CustomLogin.Enabled" />
                    <MSpacer></MSpacer>
                    @if (Tab != CustomLoginTab.BasicInformation)
                    {
                        <SButton Medium OnClick="AddConfig" Class="mr-6">
                        <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Add</SIcon>
                            <span class="ml-2">@T("Add")</span>
                        </SButton>
                    }
                    <SButton Medium OnClick="async () => await AddCustomLoginAsync(context)">@T("Submit")</SButton>
                </div>
            </FooterContent>
        </AutoHeight>        
    </MForm>
</DefaultSheetDialog>